//
//  KLineQuartzView.h
//  AppFinance
//
//  Created by wei on 12-6-10.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFQuartzView.h"

#import "AFKpiQuartzView.h"

// touch 类型
enum {
    AF_KLIN_TOUCH_NO = 0,
    AF_KLIN_TOUCH_MOVE = 1, // UIView 移动类型
    AF_KLIN_TOUCH_INFO = 2  // UIView 十字光标 信息
};

@class AFFingerView;

@protocol AFKLineQuartzViewDelegate <NSObject>
-(void)kLineQuartzViewTouchBegan;
-(void)kLineQuartzViewTouchesEnded;
-(void)kLineQuartzViewDataRefresh;
@end

@interface AFKLineQuartzView : AFQuartzView
{
    // touch 类型
    int AF_KLIN_TOUCH_TYPE;
    // view width
    float VIEW_W;
    
    BOOL isDistroy;
    
    BOOL isInitMA;
    
    NSMutableArray *kLineArray; // 所有数据
    // 1d 1w 1m 5m 15m 30m 60m,  default is 1d
    NSString *kLineType;
    
    int ALL_COUNT;      // 所有记录
    int S_MIN_DRAW_INDEX;   // 绘制 到 最小的 index 
    int S_DRAW_INDEX;   // 每次开始绘制的 index
    
    int F_DRAW_INDEX;   // 第一次绘制 的 开始 index
    
    NSArray *kLineDrawArray; // 将要绘制的数据

    NSArray *localKLindListArray;

    // touch 
    BOOL isTouchDown;    
    CGPoint startPoint;
    CGPoint currentPoint;
    float start_touch_x;
    float move_touch_x;
    float move_touch_y;
    
    
    // 计算后的基础数据
    float last_KLineHigh;
    float last_KLineLow;
    
    int KLINE_DRAW_COUNT;
    
    // MA data
    NSArray *localMA5ListArray;
    NSArray *localMA10ListArray;
    NSArray *localMA20ListArray;
    
    NSArray *drawMA5ListArray;
    NSArray *drawlMA10ListArray;
    NSArray *drawlMA20ListArray;
    
    float last_ma5;
    float last_ma10;
    float last_ma20;
    
    // 十字光标指示 的 数据
    NSDictionary *fingerDict;
    NSDictionary *prefingerDict;
    float fingerMA5;
    float fingerMA10;
    float fingerMA20;
    
    BOOL islongPress;
}

@property(nonatomic, weak) id <AFKLineQuartzViewDelegate> delegate;
@property(nonatomic, weak) AFKpiQuartzView *kpiQuartzView;
// AFFingerView 十字光标信息显示
@property(nonatomic, weak) AFFingerView *afFingerView;

- (void) initKLineArray:(NSMutableArray*)array kLineType:(NSString*)type isLast:(BOOL)isLast;
- (void) drawArrayRefresh;

- (float) lastMa5;
- (float) lastMa10;
- (float) lastMa20;

- (void) drawInContext:(CGContextRef)context rect:(CGRect)rect;
- (void) drawBackGround:(CGContextRef)context;
- (void) drawZhuTai:(CGContextRef)context;
- (void) drawMA:(CGContextRef)context;

// 十字光标 指向 的 数据
- (void) kLineCurrentPointInfo:(float)_x;
- (NSDictionary*)fingerKLine;
-(NSDictionary*)prefingerKLine;
- (float)fingerMA5;
- (float)fingerMA10;
- (float)fingerMA20;

- (void) distory;

@end
